﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using WDA.Core;
using System.Threading;
using Microsoft.Practices.Unity;

namespace Sample
{
   [ServiceContract]
   public interface IConverterService
   {
      [OperationContract]
      int ConvertToInt(double value);
      [OperationContract]
      double ConvertToDouble(int value);
   }
   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
   public class ConverterService : IConverterService
   {
		[Dependency(WDA.Core.WDAContainerNames.InternalContainerName)]
		public IUnityContainer Container { get; set; }		

		private static Logger _log = new Logger("Sample.ConverterService");

      #region IConverterService Members
      public int ConvertToInt(double value)
      {
			IResponseTimeValue respTime = Container.Resolve<IResponseTimeValue>();
			_log.WriteInfo("Converting {0} to Int32.", value);
			Thread.Sleep(respTime.Milliseconds);
         return (int)value;
      }
      public double ConvertToDouble(int value)
      {
			IResponseTimeValue respTime = Container.Resolve<IResponseTimeValue>();
			_log.WriteInfo("Converting {0} to Double.", value);
			Thread.Sleep(respTime.Milliseconds);
         return (double)value;
      }
      #endregion
   }
}
